<template>
  <div class="mod-sp__spmatcharealimit">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item prop="matchParentId">
        <el-select v-model="dataForm.matchId" placeholder="赛事">
          <el-option value="">请选择</el-option>
          <el-option v-for="item in matchList" :key="item.id" :label="item.id + ' ' + item.matchName" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="uploadPormotion()">上传</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="hasPermission('sp:spmatcharealimit:save')" type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="hasPermission('sp:spmatcharealimit:delete')" type="danger" @click="deleteHandle()">{{ $t("deleteBatch") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="downloadTemplate()">下载模板</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="id" label="序号" header-align="center" align="center"></el-table-column>
      <el-table-column prop="matchName" label="赛事" header-align="center" align="center"></el-table-column>
      <el-table-column prop="matchItemName" label="赛项" header-align="center" align="center"></el-table-column>
      <el-table-column prop="provinceName" label="省" header-align="center" align="center"></el-table-column>
      <el-table-column prop="num" label="人数限制" header-align="center" align="center"></el-table-column>
      <el-table-column prop="createDate" label="创建时间" header-align="center" align="center"></el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="hasPermission('sp:spmatcharealimit:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button v-if="hasPermission('sp:spmatcharealimit:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <!--上传-->
    <upload v-if="uploadVisible2" ref="upload2" uploadurl="/sp/spmatcharealimit/import" downloadurl="/sp/spmatcharealimit/exportError1" :matchId="dataForm.matchId" @refreshDataList="getDataList"></upload>

  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import { defineComponent, reactive, toRefs } from "vue";
import AddOrUpdate from "./spmatcharealimit-add-or-update.vue";
import Upload from "./score-upload.vue";
import app from "@/constants/app";
import qs from "qs";
import {getToken} from "@/utils/cache";
import baseService from "@/service/baseService";
export default defineComponent({
  components: {
    AddOrUpdate,
    Upload
  },
  setup() {
    const state = reactive({
      uploadVisible2: false,
      getDataListURL: "/sp/spmatcharealimit/page",
      getDataListIsPage: true,
      exportURL: "/sp/spmatcharealimit/export",
      deleteURL: "/sp/spmatcharealimit",
      deleteIsBatch: true,
      dataForm: {
        matchId: ""
      },
      matchList: [
        {
          id: "",
          matchName: ""
        }
      ],
    });
    return { ...useView(state), ...toRefs(state) };
  },
  watch: {
  },
  created() {
    this.selectMatch();
  },
  methods: {
    uploadPormotion() {
      //请先选择赛事
      if (!this.dataForm.matchId){
        this.$message({
          message: "请先选择赛事",
          type: "warning"
        });
        return;
      }

      this.uploadVisible2 = true;
      this.$nextTick(() => {
        this.$refs.upload2.init();
      });
    },

    // 导出指导老师
    downloadTemplate() {
      window.location.href = `${app.api}//sp/spmatcharealimit/download?${qs.stringify({
        ...this.dataForm,
        token: getToken()
      })}`;
    },

    // 查询所有赛事
    selectMatch() {
      baseService.get("/sp/spmatch/list").then((res) => {
        if (res.code == 0) {
          this.matchList = res.data;
        }
      });
    },



  }
});
</script>
